﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using CommonWFLibrary;
using DTBuilderLib;
using DTBuilderLib.VisualHierarchyClasses;

namespace DeepTalkWF
{
    /// <summary>
    /// Given a visual, convert it to a XML spec file which we can then use to render the whole she-bang. Returns the command spec that
    /// can be used to do the actual rendering. This isn't totally break-upable, but it works...
    /// </summary>
	public partial class ConvertVisualToCommand: LongRunningActivityBase
	{
		public ConvertVisualToCommand()
		{
			InitializeComponent();
		}


        public string MeetingOutputDirectory
        {
            get { return (string)GetValue(MeetingOutputDirectoryProperty); }
            set { SetValue(MeetingOutputDirectoryProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MeetingOutputDirectory.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MeetingOutputDirectoryProperty =
            DependencyProperty.Register("MeetingOutputDirectory", typeof(string), typeof(ConvertVisualToCommand), new PropertyMetadata(null));

        /// <summary>
        /// The scene we are to render.
        /// </summary>
        public Visual Scene
        {
            get { return (Visual)GetValue(SceneProperty); }
            set { SetValue(SceneProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Scene.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SceneProperty =
            DependencyProperty.Register("Scene", typeof(Visual), typeof(ConvertVisualToCommand), new PropertyMetadata(null));

        [Serializable]
        public class Args
        {
            public string _talkOutputDir;
            public Visual _scene;
        }

        /// <summary>
        /// Gather the arguments from the WF context and prep for the long running activity.
        /// </summary>
        /// <returns></returns>
        [LongRunningGatherArguments]
        public Args Gather()
        {
            Args a = new Args();
            a._scene = Scene;
            a._talkOutputDir = MeetingOutputDirectory;

            return a;
        }

        /// <summary>
        /// As much as we would like there to be a meeting title below -- we don't get one!
        /// It has to be "meeting" because it is hardcoded into the silverlight that is
        /// going to display this meeting. At least, for now.
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        [LongRunningMethod]
        static public Result Run(Args a)
        {
#if false
            DeepZoomBuilder bld = new DeepZoomBuilder();
            bld.BuildDirectory = a._talkOutputDir;
            var spec = bld.RenderVisualToCommand("meeting", a._scene);
            r._spec = spec;
#endif
            Result r = new Result();
            return r;
        }

        [Serializable]
        public class Result
        {
            //public DeepZoomBuilder.CommandLineSpec _spec;
        }

        /// <summary>
        /// Shove the results back into the workflow for use by folks later on down the chain.
        /// </summary>
        /// <param name="r"></param>
        [LongRunningDistributeArguments]
        public void GetResults(Result r)
        {
            //CommandInfo = r._spec;
        }
	}
}
